package com.atguigu.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.atguigu.gulimall.order.config.AlipayTemplate;
import com.atguigu.gulimall.order.service.OrderService;
import com.atguigu.gulimall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description :订单使用支付宝支付的接口
 * @Author : mayp
 * @Date: 2021-02-23 21:42
 */
@Controller
public class PayWebController {
    @Autowired
    private AlipayTemplate alipayTemplate;
    @Autowired
    private OrderService orderService;

    /**
     * 支付一个订单，支付成功后，要跳转用户的订单列表页
     * @param orderSn
     * @return
     */
    @ResponseBody
    @GetMapping(value = "/payOrder",produces = "text/html")// 要产生这种类型的数据
    public String payOrder(@RequestParam("orderSn") String orderSn)throws AlipayApiException {
        // 获取订单的支付信息
        PayVo payVo = orderService.getOrderPay(orderSn);
        String pay = alipayTemplate.pay(payVo);
        // 返回的是一个支付页面，将此页面交给浏览器就行，就能进入支付页面
        return pay;
    }

}
